layui.define([ 'form', 'laydate', 'table','outboundSubsidyApi'], function(exports) {
    var form = layui.form;
    var outboundSubsidyApi = layui.outboundSubsidyApi;
    var index = layui.index;
    var currentWorkingEnterprise = $("#currentWorkingEnterprise").val();
    $("#workUnit").val(currentWorkingEnterprise);
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                 form.on('submit(form)', function(){
                     /**
                      * 获取文件
                      */

                     var Idfile = Common.fileRequire("#IdfileDataList");
                     var banknumber = Common.fileRequire("#banknumberDataList");
                     var outboundComment = Common.fileRequire("#outboundCommentDataList");
                     var supportCertificate = Common.fileRequire("#supportCertificateDataList");
                     if(Idfile){
                         Common.alert("身份证件附件必须上传");
                     }else if(banknumber){
                         Common.alert("银行卡材料信息附件必须上传");
                     } else if(outboundComment){
                         Common.alert("出站批文附件必须上传");
                     }else if(supportCertificate){
                         Common.alert("市经费资助证明材料附件必须上传");
                     }else {
                         outboundSubsidyApi.addOutboundSubsidy($('#addForm'), function () {
                             parent.window.dataReload();
                             Common.info("添加成功");
                             Lib.closeFrame();
                         });
                     }
                });
            });
            $("#addButton-PandD").click(function(){
                form.on('submit(form)', function(){
                    /**
                     * 获取文件
                     */

                    var Idfile = Common.fileRequire("#IdfileDataList");
                    var banknumber = Common.fileRequire("#banknumberDataList");
                    var outboundComment = Common.fileRequire("#outboundCommentDataList");
                    var supportCertificate = Common.fileRequire("#supportCertificateDataList");
                    if(Idfile){
                        Common.alert("身份证件附件必须上传");
                    }else if(banknumber){
                        Common.alert("银行卡材料信息附件必须上传");
                    } else if(outboundComment){
                        Common.alert("出站批文附件必须上传");
                    }else if(supportCertificate) {
                        Common.alert("市经费资助证明材料附件必须上传");
                    }else {
                        Common.openConfirm("确认申报?", function () {
                            outboundSubsidyApi.savedeclaration($('#addForm'), function () {
                                parent.window.dataReload();
                                Common.info("保存并申报成功");
                                Lib.closeFrame();
                            });
                        }, null);
                    }
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }
    			
    }
    exports('add',view);
});